package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarService;
import com.ruoyi.system.service.ICarServiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货运服务Controller
 * 
 * @author ruoyi
 * @date 2021-06-17
 */
@RestController
@RequestMapping("/system/service/car")
public class CarServiceController extends BaseController
{
    @Autowired
    private ICarServiceService carServiceService;

    /**
     * 查询货运服务列表
     */
//    @PreAuthorize("@ss.hasPermi('system:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarService carService)
    {
        startPage();
        List<CarService> list = carServiceService.selectCarServiceList(carService);
        return getDataTable(list);
    }

    /**
     * 导出货运服务列表
     */
//    @PreAuthorize("@ss.hasPermi('system:service:export')")
    @Log(title = "货运服务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CarService carService)
    {
        List<CarService> list = carServiceService.selectCarServiceList(carService);
        ExcelUtil<CarService> util = new ExcelUtil<CarService>(CarService.class);
        return util.exportExcel(list, "service");
    }

    /**
     * 获取货运服务详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:service:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return AjaxResult.success(carServiceService.selectCarServiceById(carId));
    }

    /**
     * 新增货运服务
     */
//    @PreAuthorize("@ss.hasPermi('system:service:add')")
    @Log(title = "货运服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarService carService)
    {
        return toAjax(carServiceService.insertCarService(carService));
    }

    /**
     * 修改货运服务
     */
    @PreAuthorize("@ss.hasPermi('system:service:edit')")
    @Log(title = "货运服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarService carService)
    {
        return toAjax(carServiceService.updateCarService(carService));
    }

    /**
     * 删除货运服务
     */
    @PreAuthorize("@ss.hasPermi('system:service:remove')")
    @Log(title = "货运服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(carServiceService.deleteCarServiceByIds(carIds));
    }
}
